package com.bounds.entity;

import java.util.ArrayList;
import java.util.List;

public class Pager<T> {
	
	private int pageSize = 1 ; //ÿҳ��ʾ������
	private int currentPageNo = 1; //��ǰ�ڼ�ҳ
	private int allPages = 1; //��ҳ��
	private int allRows = 0;  //�ܼ�¼��
	private int firstRow = 0;
	private int lastRow = 0;
	
	
	public Pager() {
		super();
	}
	
	public Pager(int pageNo,int pageSize) {
		this.currentPageNo = pageNo;
		this.pageSize = pageSize;
	}
	
	public Pager(ArrayList<T> data) {
		this.data = data;
	}
	
	private List<T> data = new ArrayList<T>(); //������
	
	public T get(int i)
	{
		return data.get(i);
	}
	
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getCurrentPageNo() {
		return currentPageNo;
	}
	public void setCurrentPageNo(int currentPageNo) {
		this.currentPageNo = currentPageNo;
	}
	public int getAllPages() {
		
		if(allRows>0){
			allPages = allRows/pageSize;
			if(allRows%pageSize!=0){
				allPages ++ ;
			}
		}
		else{
			this.allPages = 1;
		}
		
		return allPages;
	}
	
	public void setAllPages(int allPages) {
		this.allPages = allPages;
	}
	public int getAllRows() {
		return allRows;
	}
	public void setAllRows(int allRows) {
		this.allRows = allRows;
	}
	public int getNextPage() {
		if(currentPageNo >=allPages){
			return allPages;
		}
		return  (currentPageNo+1) ;
	}
	
	public int getProvPage() {
		if(currentPageNo <=0){
			return 1;
		}
		
		return (currentPageNo-1);
	}
	
	public List<T> getData() {
		return data;
	}
	public void setData(final List<T> data) {
		this.data = data;
		this.firstRow = (this.currentPageNo - 1) * this.pageSize + 1;
		this.lastRow = (this.currentPageNo - 1) * this.pageSize + data.size();
	}

	public int getFirstRow() {
		return firstRow;
	}

	public void setFirstRow(int firstRow) {
		this.firstRow = firstRow;
	}

	public int getLastRow() {
		return lastRow;
	}

	public void setLastRow(int lastRow) {
		this.lastRow = lastRow;
	}
	
	
}
